package com.sky.controller.admin;


import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController("adminShopController")
@Api("店铺营业状态相关接口")
public class ShopController {

    public static final String KEY = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;


    /**
     * 设置店铺状态
     * @param status
     * @return
     */
    @PutMapping("/admin/shop/{status}")
    @ApiOperation("设置店铺状态")
    public Result setShopStatus(@PathVariable Integer status){
        log.info("店铺状态修改为:{}",status == 1? "正在营业":"已打烊");
        // 将店铺营业状态存入redis中
        redisTemplate.opsForValue().set(KEY,status);

        return Result.success("店铺状态修改成功");
    }



    @GetMapping("/admin/shop/status")
    public Result getShopStatus(){
        return Result.success(redisTemplate.opsForValue().get(KEY));
    }





}
